<?php
/**
 * Created by Pako
 * Date: 2019/3/3
 * Time: 16:05
 */

namespace App\Http\Controllers\Shop;


use App\Http\Controllers\Controller;
use App\Repositories\Product\CategoryRepository;
use App\Repositories\Shop\TemplateRepository;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    private $category;

    public function __construct(CategoryRepository $category)
    {
        $this->category = $category;
    }

    public function index()
    {
        return $this->category->list();
    }

    public function tree()
    {
        return $this->category->tree();
    }

    public function show($cat_id)
    {
        return $this->category->show($cat_id);
    }

    public function template(Request $request)
    {
        $template_ids = $request->input('template_ids', 0);
        return (new TemplateRepository($request))->getTemplateById($template_ids);
    }

    public function treeNameIds(Request $request)
    {
        $cat_id = $request->input('cat_id', 0);
        return $this->category->treeNameIds($cat_id);
    }
}